//
//  RHDeviceFilterView.m
//  RuiHeApp
//
//  Created by Yan Chen on 2025/1/3.
//

#import "RHDeviceFilterView.h"
#import "RHChoiceDeviceTypeView.h"

#define leftMargin 60

@interface RHDeviceFilterView()

@property (nonatomic ,strong) UIView *grayView;

@property (nonatomic ,strong) UIView *selectView;

@property (nonatomic ,strong) QMUILabel *typeLab;

@property (nonatomic, strong) NSMutableArray *deviceStatusArr;//设备状态button

@property (nonatomic, strong) NSMutableArray *runStatusArr;//运行状态button

@property (nonatomic, strong) NSArray *selectTypes;//已经选择的设备类型

@property (nonatomic, assign) NSInteger type; //1:设备筛选  2:部件筛选
@end
@implementation RHDeviceFilterView
-(instancetype)initWithType:(NSInteger)type
{
    if (self = [super initWithFrame:UIScreen.mainScreen.bounds]) {
        _type = type;
        [self setupUI];
    }
    return self;
}
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

-(void)setFilterDic:(NSDictionary *)filterDic
{
    [self clearAllButtonStatus];
   //设备状态
    NSString *deviceStatus = ValidNullData(filterDic[@"deviceStatus"]);
    if (deviceStatus.length>0) {
        NSArray *indexs = [deviceStatus componentsSeparatedByString:@","];
        [indexs enumerateObjectsUsingBlock:^(NSString*  _Nonnull indexStr, NSUInteger idx, BOOL * _Nonnull stop) {
            [self.deviceStatusArr enumerateObjectsUsingBlock:^(QMUIButton*  _Nonnull btn, NSUInteger idx, BOOL * _Nonnull stop) {
                if (btn.tag == [indexStr integerValue]) {
                    btn.selected = YES;
                    [self changeButtonStatus:btn];
                }
            }];
        }];
    }else{
        //全部
        QMUIButton *allBtn = [self.deviceStatusArr firstObject];
        allBtn.selected = YES;
        [self changeButtonStatus:allBtn];
    }
    
    //运行状态
    NSString *runStatus = ValidNullData(filterDic[@"runStatus"]);
    if (runStatus.length>0) {
        NSArray *indexs = [runStatus componentsSeparatedByString:@","];
        [indexs enumerateObjectsUsingBlock:^(NSString*  _Nonnull indexStr, NSUInteger idx, BOOL * _Nonnull stop) {
            [self.runStatusArr enumerateObjectsUsingBlock:^(QMUIButton*  _Nonnull btn, NSUInteger idx, BOOL * _Nonnull stop) {
                if (btn.tag == [indexStr integerValue]) {
                    btn.selected = YES;
                    [self changeButtonStatus:btn];
                }
            }];
        }];
    }else{
        //全部
        QMUIButton *allBtn = [self.runStatusArr firstObject];
        allBtn.selected = YES;
        [self changeButtonStatus:allBtn];
    }
    
    //设备类型
    NSString *deviceType = ValidNullData(filterDic[@"deviceType"]);
    if (deviceType.length>0) {
        self.selectTypes = [deviceType componentsSeparatedByString:@","];
    }else{
        self.selectTypes = nil;
    }
    [self updateDeviceTypeLab];
}

-(void)clearAllButtonStatus
{
    [self.deviceStatusArr enumerateObjectsUsingBlock:^(QMUIButton*  _Nonnull btn, NSUInteger idx, BOOL * _Nonnull stop) {
        btn.selected = NO;
        [self changeButtonStatus:btn];
    }];
    [self.runStatusArr enumerateObjectsUsingBlock:^(QMUIButton*  _Nonnull btn, NSUInteger idx, BOOL * _Nonnull stop) {
        btn.selected = NO;
        [self changeButtonStatus:btn];
    }];
}

-(void)setupUI
{
    self.deviceStatusArr = [NSMutableArray array];
    self.runStatusArr = [NSMutableArray array];
    kWeakSelf;
    _grayView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kUI_WINDOW_W, kUI_WINDOW_H)];
    _grayView.backgroundColor = UIColor.whiteColor;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(diss)];
    [_grayView addGestureRecognizer:tap];
    
    [self addSubview:_grayView];
    _selectView = [[UIView alloc]initWithFrame:CGRectMake(kUI_WINDOW_W, 0, kUI_WINDOW_W - leftMargin, kUI_WINDOW_H)];
    _selectView.backgroundColor = UIColor.whiteColor;
    [self addSubview:_selectView];
    
    
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kUI_WINDOW_W - leftMargin, kSafe_top+44)];
    [_selectView addSubview:headerView];
    
    QMUILabel *titleLab =  [QMUILabel labelWithFont:kBOLDSYSTEMFONT(16) textColor:kCOLOR_HEX(@"#3F4443") textAligment:NSTextAlignmentLeft];
    titleLab.backgroundColor = UIColor.whiteColor;
    titleLab.text = self.type==1?@"设备筛选".rh_localized:@"部件筛选".rh_localized;
    [headerView addSubview:titleLab];
    
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.bottom.mas_offset(-10);
    }];

    UIScrollView *scrollView = [[UIScrollView alloc]init];
    scrollView.backgroundColor = CFTabViewBgColor;
    [_selectView addSubview:scrollView];
    
    UIView *contentView = kView;
    contentView.backgroundColor = CFTabViewBgColor;
    [scrollView addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
        make.width.equalTo(weakSelf.selectView);
    }];
    
    //-------------------设备状态
    UIView *statusView = kView;
    statusView.backgroundColor = UIColor.whiteColor;
    [contentView addSubview:statusView];
    [statusView rounded:8 width:1 color:kBorderColor];
    [statusView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_offset(15);
        make.right.mas_offset(-15);
        
    }];
    
    QMUILabel *statusTitleLab = [QMUILabel labelWithFont:kBOLDSYSTEMFONT(14) textColor:kCOLOR_HEX(@"#303133") textAligment:NSTextAlignmentLeft];
    [statusView addSubview:statusTitleLab];
    statusTitleLab.text = self.type==1? @"设备状态".rh_localized:@"部件状态".rh_localized;
    [statusTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(10);
        make.top.mas_offset(15);
        make.right.mas_offset(-10);
    }];
    
    CGFloat btnWidth = (_selectView.width - 30-30)/2;
    NSArray *deviceStatuIndexs = @[@"",@"0",@"1"];
    NSArray *statusTitles = @[@"全部".rh_localized,@"正常".rh_localized,@"离线".rh_localized];
    if (self.type == 2) {//部件筛选
        deviceStatuIndexs = @[@"",@"1",@"0"];
    }
    __block QMUIButton *lastStatusBtn;
    [statusTitles enumerateObjectsUsingBlock:^(NSString*  _Nonnull title, NSUInteger idx, BOOL * _Nonnull stop) {
        QMUIButton *btn = [QMUIButton buttonWithTitle:title titleColor:kCOLOR_HEX(@"#8B8D92") titleFont:kSYSTEMFONT(14)];
        NSString *index = [deviceStatuIndexs safeObjectAtIndex:idx];
        if (index.length>0) {
            btn.tag = [index integerValue];
        }else{
            btn.tag = 100+idx;
        }
        
        [self.deviceStatusArr addObject:btn];
        [btn setCornerRadius:8];
        btn.qmui_borderColor = kCOLOR_HEX(@"#CDD0D6");
        btn.qmui_borderWidth = 1;
        btn.qmui_borderPosition = QMUIViewBorderPositionTop|QMUIViewBorderPositionLeft|QMUIViewBorderPositionRight|QMUIViewBorderPositionBottom;
        btn.backgroundColor = kCOLOR_HEX(@"#FCFBFB");
        [btn setTitleColor:kCOLOR_HEX(@"#8B8D92") forState:UIControlStateNormal];
        [btn setTitleColor:kCOLOR_HEX(@"#05C79D") forState:UIControlStateSelected];
        [statusView addSubview:btn];
        [btn addTarget:self action:@selector(clickDeviceStatus:) forControlEvents:UIControlEventTouchUpInside];
        if (lastStatusBtn) {
            if (idx%2==0) {//换行
                [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.width.height.equalTo(lastStatusBtn);
                    make.left.mas_offset(10);
                    make.top.equalTo(lastStatusBtn.mas_bottom).offset(10);
                }];
            }else{
                [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.width.height.equalTo(lastStatusBtn);
                    make.left.equalTo(lastStatusBtn.mas_right).offset(10);
                    make.top.equalTo(lastStatusBtn);
                }];
            }
        }else{
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_offset(10);
                make.top.equalTo(statusTitleLab.mas_bottom).offset(15);
                make.width.offset(btnWidth);
                make.height.offset(34);
            }];
        }
        lastStatusBtn = btn;
    }];
    [lastStatusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(-10);
    }];
    
    //-------------------运行状态
    UIView *runView = kView;
    runView.backgroundColor = UIColor.whiteColor;
    [contentView addSubview:runView];
    [runView rounded:8 width:1 color:kBorderColor];
    [runView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.equalTo(statusView.mas_bottom).offset(15);
        make.right.mas_offset(-15);
        
    }];
    
    QMUILabel *runTitleLab = [QMUILabel labelWithFont:kBOLDSYSTEMFONT(14) textColor:kCOLOR_HEX(@"#303133") textAligment:NSTextAlignmentLeft];
    [runView addSubview:runTitleLab];
    runTitleLab.text = @"运行状态".rh_localized;
    [runTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(10);
        make.top.mas_offset(15);
        make.right.mas_offset(-10);
    }];
    
   
    NSArray *runTitles = @[@"全部".rh_localized,@"正常".rh_localized,@"告警".rh_localized,@"故障".rh_localized];
    NSArray *runStatusIndexs = @[@"",@"0",@"1",@"2"];
    if (self.type == 2) {//部件筛选
        runTitles = @[@"全部".rh_localized,@"正常".rh_localized,@"告警".rh_localized,@"故障".rh_localized,@"保护".rh_localized];
        runStatusIndexs = @[@"",@"0",@"1",@"2",@"3"];
    }
    __block QMUIButton *lastRunBtn;
    [runTitles enumerateObjectsUsingBlock:^(NSString*  _Nonnull title, NSUInteger idx, BOOL * _Nonnull stop) {
        QMUIButton *btn = [QMUIButton buttonWithTitle:title titleColor:kCOLOR_HEX(@"#8B8D92") titleFont:kSYSTEMFONT(14)];
        NSString *index = [runStatusIndexs safeObjectAtIndex:idx];
        if (index.length>0) {
            btn.tag = [index integerValue];
        }else{
            btn.tag = 200+idx;
        }
        [self.runStatusArr addObject:btn];
        [btn setCornerRadius:8];
        btn.qmui_borderColor = kCOLOR_HEX(@"#CDD0D6");
        btn.qmui_borderWidth = 1;
        btn.qmui_borderPosition = QMUIViewBorderPositionTop|QMUIViewBorderPositionLeft|QMUIViewBorderPositionRight|QMUIViewBorderPositionBottom;
        btn.backgroundColor = kCOLOR_HEX(@"#FCFBFB");
        [btn setTitleColor:kCOLOR_HEX(@"#8B8D92") forState:UIControlStateNormal];
        [btn setTitleColor:kCOLOR_HEX(@"#05C79D") forState:UIControlStateSelected];
        [btn addTarget:self action:@selector(clickRunStatus:) forControlEvents:UIControlEventTouchUpInside];
        
        [runView addSubview:btn];
        if (lastRunBtn) {
            if (idx%2==0) {//换行
                [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.width.height.equalTo(lastRunBtn);
                    make.left.mas_offset(10);
                    make.top.equalTo(lastRunBtn.mas_bottom).offset(10);
                }];
            }else{
                [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.width.height.equalTo(lastRunBtn);
                    make.left.equalTo(lastRunBtn.mas_right).offset(10);
                    make.top.equalTo(lastRunBtn);
                }];
            }
        }else{
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_offset(10);
                make.top.equalTo(runTitleLab.mas_bottom).offset(15);
                make.width.offset(btnWidth);
                make.height.offset(34);
            }];
        }
        lastRunBtn = btn;
    }];
    [lastRunBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(-10);
    }];
    
    //------------------设备类型
    if (self.type == 1) {
        UIView *typeView = kView;
        typeView.backgroundColor = UIColor.whiteColor;
        [contentView addSubview:typeView];
        [typeView rounded:8 width:1 color:kBorderColor];
        [typeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(15);
            make.top.equalTo(runView.mas_bottom).offset(15);
            make.right.mas_offset(-15);
            
        }];
        
        QMUILabel *typeTitleLab = [QMUILabel labelWithFont:kBOLDSYSTEMFONT(14) textColor:kCOLOR_HEX(@"#303133") textAligment:NSTextAlignmentLeft];
        [typeView addSubview:typeTitleLab];
        typeTitleLab.text = @"设备类型".rh_localized;
        [typeTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.mas_offset(10);
            make.right.mas_offset(-10);
        }];
        
        UIView *typeContentView = kView;
        [typeView addSubview:typeContentView];
        [typeContentView rounded:8];
        typeContentView.backgroundColor = CFTabViewBgColor;
        [typeContentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(15);
            make.right.mas_offset(-15);
            make.top.equalTo(typeTitleLab.mas_bottom).offset(15);
            make.height.offset(44);
            make.bottom.mas_offset(-15);
        }];
        
        _typeLab = [QMUILabel labelWithFont:kSYSTEMFONT(14) textColor:kCOLOR_HEX(@"#303133") textAligment:NSTextAlignmentLeft];
        [typeContentView addSubview:_typeLab];
        _typeLab.text = @"全部".rh_localized;
        [_typeLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(15);
            make.centerY.mas_offset(0);
        }];
        
        UIImageView *arrow = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow"]];
        [typeContentView addSubview:arrow];
        [arrow mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.offset(16);
            make.right.mas_offset(-15);
            make.centerY.mas_offset(0);
        }];
        
        
        UITapGestureRecognizer *tap_select = [[UITapGestureRecognizer alloc]init];
        [tap_select addTarget:self action:@selector(selectDeviceType)];
        [typeContentView addGestureRecognizer:tap_select];
        //封底
        [typeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_offset(-15);
        }];
    }else{
        //封底
        [runView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_offset(-15);
        }];
    }
    
    
    
    //---------底部按钮
    UIView *bottomView = kView;
    [_selectView addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.bottom.mas_offset(0);
        make.height.offset(44+15+(kSafe_bottom>0?kSafe_bottom:15));
    }];
    
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.top.equalTo(headerView.mas_bottom);
        make.bottom.equalTo(bottomView.mas_top);
    }];

    
    QMUIButton *cancelBtn = [[QMUIButton alloc]init];
    [cancelBtn setTitle:@"取消".rh_localized forState:UIControlStateNormal];
    cancelBtn.titleLabel.font = kSYSTEMFONT(16);
    [cancelBtn setTitleColor:kCOLOR_HEX(@"#CCCCCC") forState:UIControlStateNormal];
    [cancelBtn rounded:8 width:1 color:kCOLOR_HEX(@"#CCCCCC")];

  
    [cancelBtn setBackgroundColor:UIColor.whiteColor];
    [cancelBtn setCornerRadius:8];
    [bottomView addSubview:cancelBtn];
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(15);
        make.left.mas_offset(15);
        make.height.offset(44);
    }];
    
    QMUIButton *sureBtn = [[QMUIButton alloc]init];
    [sureBtn setTitle:@"确定".rh_localized forState:UIControlStateNormal];
    sureBtn.titleLabel.font = kSYSTEMFONT(16);
    [sureBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    [sureBtn setBackgroundColor:CMainColorGreen];
    [sureBtn rounded:8];
    [bottomView addSubview:sureBtn];
    [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(cancelBtn);
        make.left.equalTo(cancelBtn.mas_right).mas_offset(15);
        make.right.mas_offset(-15);
        make.width.height.equalTo(cancelBtn);
    }];
    
 
    [[cancelBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        [weakSelf diss];
    }];
    
    [[sureBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        [weakSelf sureAction];
    }];
}

//选择设备状态
-(void)clickDeviceStatus:(QMUIButton*)btn
{
    btn.selected = !btn.selected;
    if (btn.selected) {
        [self changeButtonStatus:btn];
        
        if (btn.tag == 100) {
            //点击了全部,把其他的按钮取消
            [self.deviceStatusArr enumerateObjectsUsingBlock:^(QMUIButton*  _Nonnull button, NSUInteger idx, BOOL * _Nonnull stop) {
                if (idx == 0) return;
                button.selected = NO;
                [self changeButtonStatus:button];
            }];
        }else{
            //点击了其他,全部按钮取消掉
            QMUIButton *allBtn = [self.deviceStatusArr safeObjectAtIndex:0];
            allBtn.selected = NO;
            [self changeButtonStatus:allBtn];
        }
    }else{
        [self changeButtonStatus:btn];
    }
    
}

//选择运行状态
-(void)clickRunStatus:(QMUIButton*)btn
{
    btn.selected = !btn.selected;
    if (btn.selected) {
        [self changeButtonStatus:btn];
        
        if (btn.tag == 200) {
            //点击了全部,把其他的按钮取消
            [self.runStatusArr enumerateObjectsUsingBlock:^(QMUIButton*  _Nonnull button, NSUInteger idx, BOOL * _Nonnull stop) {
                if (idx == 0) return;
                button.selected = NO;
                [self changeButtonStatus:button];
            }];
        }else{
            //点击了其他,全部按钮取消掉
            QMUIButton *allBtn = [self.runStatusArr safeObjectAtIndex:0];
            allBtn.selected = NO;
            [self changeButtonStatus:allBtn];
        }
    }else{
        [self changeButtonStatus:btn];
    }
}

-(void)changeButtonStatus:(QMUIButton*)btn
{
  
    if(btn.isSelected){
        btn.qmui_borderColor = kCOLOR_HEX_A(@"#05C79D",1);
        btn.backgroundColor  = kCOLOR_HEX_A(@"#05C79D",0.15);
    }else{
        btn.qmui_borderColor = kCOLOR_HEX(@"#CDD0D6");
        btn.backgroundColor  = kCOLOR_HEX(@"#FCFBFB");
    }
}

//选择设备类型
-(void)selectDeviceType
{
    [self getPlantType];
}

#pragma mark -------- 获取电站,设备类型
-(void)getPlantType
{
    [QMUITips showLoadingInView:self];
    [RHDevTypeModel startGetWithCompletionAPIKey:H_plantTypeOfGroup3 argument:@{} requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        if(resultModel.code == 200){
           
            [self showPlantTypeList:resultModel.data];
        }
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
    }];
}

-(void)showPlantTypeList:(NSArray*)typeList
{
    RHChoiceDeviceTypeView *choiceView = [[RHChoiceDeviceTypeView alloc] init];
    choiceView.plantTypeList = typeList;
    choiceView.curTypes = self.selectTypes;
    [choiceView scorllToCurrentValue];
    [choiceView showAnimation];
    kWeakSelf;
    choiceView.choiceResultBlock = ^(NSArray *types) {
        if (types==nil) {
            return;
        }
        self.selectTypes = types;
        [weakSelf updateDeviceTypeLab];
        
    };
}

-(void)updateDeviceTypeLab
{
    if (self.selectTypes.count == 0) {
        self.typeLab.text = @"全部".rh_localized;
    }else{
        __block NSMutableString *typeString = [NSMutableString string];
        [self.selectTypes enumerateObjectsUsingBlock:^(NSString*  _Nonnull type, NSUInteger idx, BOOL * _Nonnull stop) {
            [typeString appendString:type];
            if (idx != self.selectTypes.count-1) {
                [typeString appendString:@","];
            }
        }];
        self.typeLab.text = typeString;
    }
}

-(void)sureAction
{
    //设备状态
    NSMutableString *deviceStatus = [NSMutableString string];
    [self.deviceStatusArr enumerateObjectsUsingBlock:^(QMUIButton*  _Nonnull btn, NSUInteger idx, BOOL * _Nonnull stop) {
        if (idx == 0) {
            return;
        }else{
            if (btn.isSelected) {
                [deviceStatus appendFormat:@"%ld,",btn.tag];
            }
        }
        
    }];
    
    if (deviceStatus.length>0) {
        deviceStatus = [deviceStatus qmui_stringByRemoveLastCharacter];
    }
    //运行状态
    NSMutableString *runStatus = [NSMutableString string];
    [self.runStatusArr enumerateObjectsUsingBlock:^(QMUIButton*  _Nonnull btn, NSUInteger idx, BOOL * _Nonnull stop) {
        if (idx == 0) {
            return;
        }else{
            if (btn.isSelected) {
                [runStatus appendFormat:@"%ld,",btn.tag];
            }
        }
    }];
    if (runStatus.length>0) {
        runStatus = [runStatus qmui_stringByRemoveLastCharacter];
    }
    //设备类型
    NSMutableString *deviceType = [NSMutableString string];
    [self.selectTypes enumerateObjectsUsingBlock:^(NSString*  _Nonnull type, NSUInteger idx, BOOL * _Nonnull stop) {
        [deviceType appendFormat:@"%@,",type];
    }];
    if (deviceType.length>0) {
        deviceType = [deviceType qmui_stringByRemoveLastCharacter];
    }
    
    
    NSDictionary *filterDic = @{
        @"deviceStatus":ValidNullData(deviceStatus),
        @"runStatus":ValidNullData(runStatus),
        @"deviceType":ValidNullData(deviceType)
    };
    if (self.filterBlock) {
        self.filterBlock(filterDic);
    }
    [self diss];
}





-(void)showInWindowAnimate
{
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    self.grayView.backgroundColor = kCOLOR_HEX_A(@"000000", 0);
    self.selectView.x = kUI_WINDOW_W;
    [UIView animateWithDuration:0.3 animations:^{
        self.grayView.backgroundColor = kCOLOR_HEX_A(@"000000", 0.4);
        self.selectView.x = leftMargin;
    }];
}

-(void)diss
{
    [UIView animateWithDuration:0.3 animations:^{
            self.grayView.backgroundColor = kCOLOR_HEX_A(@"000000", 0);
            self.selectView.x = kUI_WINDOW_W;
        } completion:^(BOOL finished) {
            [self removeFromSuperview];
        }];
}
@end
